package com.gohome.gohomechat.presenter;

import com.gohome.gohomechat.model.AddFriendModel;
import com.gohome.gohomechat.model.entify.Friend;
import com.gohome.gohomechat.model.modellistener.AddFriendModelInterface;
import com.gohome.gohomechat.presenter.callback.AddFriendCallBack;
import com.gohome.gohomechat.presenter.callback.FindFriendCallBack;
import com.gohome.gohomechat.presenter.presenterlistener.AddFriendPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.AddFriendViewInterface;

import java.util.List;

/**
 * Created by dllo on 16/3/2.
 */
public class AddFriendPresenter extends BasePresenter<AddFriendViewInterface> implements AddFriendPresenterInterface {
    private AddFriendViewInterface addFriendViewInterface;
    private AddFriendModelInterface addFriendModelInterface;

    public AddFriendPresenter(AddFriendViewInterface addFriendViewInterface) {
        this.addFriendViewInterface = addFriendViewInterface;
        this.addFriendModelInterface = new AddFriendModel();
    }

    @Override
    public void addFriend() {
        addFriendViewInterface.showDialog();
        addFriendModelInterface.addFriend(addFriendViewInterface.userName(),
                addFriendViewInterface.reason(), new AddFriendCallBack() {
                    @Override
                    public void addFriendSuccess() {
                        addFriendViewInterface.dismissDialog();
                        addFriendViewInterface.addFriendSuccess();

                    }

                    @Override
                    public void addFriendFailed() {
                        addFriendViewInterface.dismissDialog();
                        addFriendViewInterface.addFriendFailed();
                    }
                });

    }

    @Override
    public void showAlertDialog() {
        addFriendViewInterface.showAlertDialog();
    }

    @Override
    public void refreshData() {
        addFriendViewInterface.showDialog();
        addFriendModelInterface.findFriend(addFriendViewInterface.userName(), new FindFriendCallBack() {
            @Override
            public void findFriendSuccess(List<Friend> datas) {
                addFriendViewInterface.dismissDialog();
                addFriendViewInterface.updateData(datas);
            }

            @Override
            public void findFriendFailed() {
                addFriendViewInterface.dismissDialog();
                addFriendViewInterface.updateDataFailed();
            }
        });
    }
}
